package com.siam.package_rider.controller.admin;

import com.siam.package_common.constant.BasicResultCode;
import com.siam.package_common.constant.Quantity;
import com.siam.package_common.entity.BasicResult;
import com.siam.package_common.exception.StoneCustomerException;
import com.siam.package_merchant.entity.Merchant;
import com.siam.package_order.entity.Order;
import com.siam.package_order.model.param.OrderParam;
import com.siam.package_rider.model.param.TbDeliveryOrderParam;
import com.siam.package_rider.service.TbDeliveryOrderService;
import com.siam.package_user.entity.Member;
import com.siam.package_user.util.TokenUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * ---------------------------
 * 配送订单表 (TbDeliveryOrderController)         
 * ---------------------------
 * 作者：  高品
 * 时间：  2025-03-29 18:55:18
 * ---------------------------
 */
@RestController
@RequestMapping("/rest/admin/deliveryOrder")
public class AdminDeliveryOrderController {

	@Autowired
	private TbDeliveryOrderService tbDeliveryOrderService;

	/**
	 * 保存配送订单表
	 * @param param
	 * @return
	 */	
	@PostMapping(value="/insert")
	public BasicResult insert(@RequestBody TbDeliveryOrderParam param) {
		tbDeliveryOrderService.insert(param);
		return BasicResult.success();
	}

    /**
     * 删除配送订单表
     * @param id
     * @return
     */
	@PostMapping(value="/delete")
	public BasicResult delete(@RequestParam Long id) {
		tbDeliveryOrderService.delete(id);
		return BasicResult.success();
	}

    /**
     * 批量删除配送订单表
     * @param idList
     * @return
     */
	@PostMapping(value="/batchDelete")
	public BasicResult batchDelete(@RequestBody List<Long> idList) {
		tbDeliveryOrderService.batchDelete(idList);
		return BasicResult.success();
	}

	/**
	 * 修改配送订单表
	 * @param param
	 * @return
	 */
	@PostMapping(value="/update")
	public BasicResult update(@RequestBody TbDeliveryOrderParam param) {
		tbDeliveryOrderService.update(param);
		return BasicResult.success();
	}

    /**
     * 基础分页查询
     * @param param
     * @return
     */    
	@PostMapping(value="/page")
	public BasicResult page(@RequestBody TbDeliveryOrderParam param) {
		return BasicResult.success(tbDeliveryOrderService.page(param));
	}
	
    /**
     * 根据主键查询
     * @param id
     * @return
     */ 	
	@PostMapping(value="/findById")
	public BasicResult findById(@RequestParam Long id) {
		return BasicResult.success(tbDeliveryOrderService.findById(id));
	}

	@ApiOperation(value = "查询所有订单标签页的待处理数量")
	@PostMapping(value = "/selectAllTabWaitHandleNum")
	public BasicResult selectAllTabWaitHandleNum(@RequestBody @Validated(value = {}) TbDeliveryOrderParam param){
		Map map = this.tbDeliveryOrderService.selectAllTabWaitHandleNum(param);
		return BasicResult.success(map);
	}

	/**
	 * 查询订单统计数据
	 * PS；一次性将所有数据全部查出来，而不是每次选择时间段时来实时请求数据
	 */
	@PostMapping(value = "/statistic")
	public BasicResult statisticOrder(@RequestBody @Validated(value = {}) TbDeliveryOrderParam param) throws ParseException {
		Map map = tbDeliveryOrderService.statistic(param);
		return BasicResult.success(map);
	}

	@ApiOperation(value = "修改订单状态")
	@PostMapping(value = "/updateStatus")
	public BasicResult updateStatus(@RequestBody @Validated(value = {}) TbDeliveryOrderParam param){
		tbDeliveryOrderService.updateStatus(param);
		return BasicResult.success();
	}
}